//
//  SubViewController.m
//  ShandsMod
//
//  Created by zh s on 2023/3/22.
//  Copyright © 2023 zh_s. All rights reserved.
//

#import "SubViewController.h"
#import "GWInitiateWorkSheetV.h"


@interface SubViewController ()
/**! titleLab*/
@property (nonatomic, strong) UILabel *titleLab;
@property (nonatomic, strong) UIImageView *linkImg;
@property (nonatomic, strong) UIImageView *linkIDImg;

/**! linkExplainLab*/
@property (nonatomic, strong) UILabel *linkExplainLab;
/**! linkExplainLab*/
@property (nonatomic, strong) UILabel *linkDateLab;
@end

@implementation SubViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.nav.hidden = YES;
    self.view.backgroundColor = MAIN_BACKCOLOR;
    UIImageView *backV = [[UIImageView alloc] init];
    [self.view addSubview:backV];
    backV.image = IMAGE_NAME(@"bg_home_screen");
    backV.contentMode = UIViewContentModeScaleAspectFit;
    backV.clipsToBounds = YES;
    backV.frame = CGRectMake(-100, -260, SCREEN_WIDTH + 150, SCREEN_HEIGHT + 300);
    [self.view sendSubviewToBack:backV];

    
    UIButton *linkBtn = [BaseViewFactory buttonWithFrame:CGRectZero font:FONT_NAME(FONT_Semibold, 16) title:@"开始连接" titleColor:UIColor.whiteColor backColor:MAIN_ACTIVE_COLOR];
    [self.view addSubview:linkBtn];
    linkBtn.layer.borderColor = UIColor.whiteColor.CGColor;
    linkBtn.layer.borderWidth = 1.f;
    GWRadius(linkBtn, 20);
    [linkBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.view.mas_centerX);
        make.bottom.mas_equalTo(self.view.mas_bottom).mas_offset(-240);
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH - 170, 40));
    }];
    [linkBtn setTitle:@"断开连接" forState:UIControlStateSelected];
    [linkBtn addTarget:self action:@selector(linkNetworkClick:) forControlEvents:UIControlEventTouchUpInside];
    
    UIView *networkLineV = [BaseViewFactory viewWithFrame:CGRectZero color:RGBA(255, 255, 255, 0.3)];
    [self.view addSubview:networkLineV];
    [networkLineV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.view.mas_centerX);
        make.bottom.mas_equalTo(linkBtn.mas_bottom).mas_offset(-HEIGHT_CONSTARIN(68));
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH - 190, 32));
    }];
    GWRadius(networkLineV, 10);
    
    UIImageView *iconImg = [[UIImageView alloc] init];
    [networkLineV addSubview:iconImg];
    iconImg.image = IMAGE_NAME(@"icon_test_linkImg");
    [iconImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(12);
        make.centerY.mas_equalTo(networkLineV.mas_centerY);
        make.width.height.mas_equalTo(14);
    }];
    
    
    
    
    UIView *reconnectionView = [BaseViewFactory viewWithFrame:CGRectZero color:MAIN_ACTIVE_COLOR];
    [networkLineV addSubview:reconnectionView];
    [reconnectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(networkLineV.mas_right);
        make.centerY.mas_equalTo(networkLineV.mas_centerY);
        make.height.mas_equalTo(32);
        make.width.mas_equalTo(41);
    }];
    GWRadius(reconnectionView, 10);
    
    
    UIImageView *reconnectionImg = [[UIImageView alloc] init];
    [networkLineV addSubview:reconnectionImg];
    reconnectionImg.userInteractionEnabled = YES;
    reconnectionImg.image = IMAGE_NAME(@"icon_test_reconnection_white");
    [reconnectionImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(reconnectionView.mas_centerY);
        make.centerX.mas_equalTo(reconnectionView.mas_centerX);
        make.width.height.mas_equalTo(19);
    }];

    [reconnectionView addTapGestureTarget:self action:@selector(reconnectionViewClick)];


    UILabel *titleLab = [BaseViewFactory labelWithFrame:CGRectZero textColor:UIColor.whiteColor font:FONT_NAME(FONT_Regular, 14) textAligment:NSTextAlignmentCenter andtext:@"澳大利亚专线"];
    [networkLineV addSubview:titleLab];
    [titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(iconImg.mas_right).mas_offset(5);
        make.centerY.mas_equalTo(networkLineV.mas_centerY);
        make.right.mas_equalTo(networkLineV.mas_right).mas_offset(-41);
        make.height.mas_equalTo(22);
    }];
    _titleLab = titleLab;
    
    
    UIImageView *linkImg = [[UIImageView alloc] init];
    [self.view addSubview:linkImg];
    linkImg.alpha = 0.6;
    linkImg.backgroundColor = RandomColor;
    linkImg.contentMode = UIViewContentModeScaleAspectFill;
    linkImg.clipsToBounds = YES;
    linkImg.image = IMAGE_NAME(@"icon_test_noLink");
    [linkImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(networkLineV.mas_top).mas_offset(-HEIGHT_CONSTARIN(60));
        make.centerX.mas_equalTo(self.view.mas_centerX);
        make.width.height.mas_equalTo(225);
    }];
    _linkImg = linkImg;
    
    UIImageView *linkIDImg = [[UIImageView alloc] init];
    linkIDImg.contentMode = UIViewContentModeScaleAspectFit;
    linkIDImg.clipsToBounds = YES;
    [linkImg addSubview:linkIDImg];
    linkIDImg.image = IMAGE_NAME(@"icon_test_link");
    [linkIDImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(58);
        make.centerX.mas_equalTo(linkImg.mas_centerX);
        make.width.mas_equalTo(45);
        make.height.mas_equalTo(82);
    }];
    _linkIDImg = linkIDImg;
    
    UILabel *linkExplainLab = [BaseViewFactory labelWithFrame:CGRectZero textColor:UIColor.whiteColor font:FONT_NAME(FONT_Regular, 15) textAligment:NSTextAlignmentCenter andtext:@"未连接"];
    [linkImg addSubview:linkExplainLab];
    [linkExplainLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(linkImg.mas_bottom).mas_offset(-53);
        make.centerX.mas_equalTo(linkImg.mas_centerX);
        make.width.mas_equalTo(60);
        make.height.mas_equalTo(25);
    }];
    _linkExplainLab = linkExplainLab;
    
    UILabel *linkDateLab = [BaseViewFactory labelWithFrame:CGRectZero textColor:UIColor.whiteColor font:FONT_NAME(@"DINCond-Bold", 36) textAligment:NSTextAlignmentCenter andtext:@"连接时间"];
    linkDateLab.hidden = YES;
    [linkImg addSubview:linkDateLab];
    [linkDateLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(174);
        make.centerX.mas_equalTo(linkImg.mas_centerX);
        make.width.mas_equalTo(225);
        make.height.mas_equalTo(58);
    }];
    _linkDateLab = linkDateLab;

}


#pragma mark ----- 点击事件
///链接/断开 网络
-(void)linkNetworkClick:(UIButton *)sender {
    sender.selected = !sender.selected;
    if (sender.selected) {
        sender.backgroundColor = UIColor.clearColor;
        _linkImg.image = IMAGE_NAME(@"icon_test_link");
    }else{
        sender.backgroundColor = MAIN_ACTIVE_COLOR;
        _linkImg.image = IMAGE_NAME(@"icon_test_noLink");
    }
    
}

///切换节点
- (void)reconnectionViewClick {
    SHOW_TIPS(@"切换节点");
    WS(weakSelf);
    [GWInitiateWorkSheetV showDataTableViewWithTitle:@"切换线路" withUrl:@"" defaultSelValue:0 withBodyDic:@{} resultBlock:^(id  _Nonnull model, NSInteger index) {
        weakSelf.titleLab.text = model;
    }];
}
@end
